
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 01/30/2014 14:28:25
-- Generated from EDMX file: E:\Projects\Social Survivor\BackEnd\SocialSurvivor\Database\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [TestDb];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CharacterCharacterItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CharacterItemSet] DROP CONSTRAINT [FK_CharacterCharacterItem];
GO
IF OBJECT_ID(N'[dbo].[FK_ItemTypeCharacterItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CharacterItemSet] DROP CONSTRAINT [FK_ItemTypeCharacterItem];
GO
IF OBJECT_ID(N'[dbo].[FK_CharacterActionLog]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ActionLogSet] DROP CONSTRAINT [FK_CharacterActionLog];
GO
IF OBJECT_ID(N'[dbo].[FK_TileTypeTile]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TileSet] DROP CONSTRAINT [FK_TileTypeTile];
GO
IF OBJECT_ID(N'[dbo].[FK_PlaceTile]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TileSet] DROP CONSTRAINT [FK_PlaceTile];
GO
IF OBJECT_ID(N'[dbo].[FK_TileActionLog]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ActionLogSet] DROP CONSTRAINT [FK_TileActionLog];
GO
IF OBJECT_ID(N'[dbo].[FK_UserAccountCharacter]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CharacterSet] DROP CONSTRAINT [FK_UserAccountCharacter];
GO
IF OBJECT_ID(N'[dbo].[FK_PlaceCharacter]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PlaceSet] DROP CONSTRAINT [FK_PlaceCharacter];
GO
IF OBJECT_ID(N'[dbo].[FK_IslandPlace]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PlaceSet] DROP CONSTRAINT [FK_IslandPlace];
GO
IF OBJECT_ID(N'[dbo].[FK_IslandIslandQue]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IslandQueSet] DROP CONSTRAINT [FK_IslandIslandQue];
GO
IF OBJECT_ID(N'[dbo].[FK_CharacterIslandQue]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IslandQueSet] DROP CONSTRAINT [FK_CharacterIslandQue];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserAccountSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserAccountSet];
GO
IF OBJECT_ID(N'[dbo].[CharacterSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CharacterSet];
GO
IF OBJECT_ID(N'[dbo].[CharacterItemSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CharacterItemSet];
GO
IF OBJECT_ID(N'[dbo].[ItemTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ItemTypeSet];
GO
IF OBJECT_ID(N'[dbo].[PlaceSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PlaceSet];
GO
IF OBJECT_ID(N'[dbo].[IslandSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IslandSet];
GO
IF OBJECT_ID(N'[dbo].[TileSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TileSet];
GO
IF OBJECT_ID(N'[dbo].[TileTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TileTypeSet];
GO
IF OBJECT_ID(N'[dbo].[ActionLogSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ActionLogSet];
GO
IF OBJECT_ID(N'[dbo].[IslandQueSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IslandQueSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserAccountSet'
CREATE TABLE [dbo].[UserAccountSet] (
    [Id] uniqueidentifier  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'CharacterSet'
CREATE TABLE [dbo].[CharacterSet] (
    [Id] uniqueidentifier  NOT NULL,
    [UserAccount_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'CharacterItemSet'
CREATE TABLE [dbo].[CharacterItemSet] (
    [Id] uniqueidentifier  NOT NULL,
    [Amount] nvarchar(max)  NOT NULL,
    [Character_Id] uniqueidentifier  NOT NULL,
    [ItemType_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'ItemTypeSet'
CREATE TABLE [dbo].[ItemTypeSet] (
    [Id] uniqueidentifier  NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'PlaceSet'
CREATE TABLE [dbo].[PlaceSet] (
    [Id] uniqueidentifier  NOT NULL,
    [IslandId] uniqueidentifier  NOT NULL,
    [Character_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'IslandSet'
CREATE TABLE [dbo].[IslandSet] (
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'TileSet'
CREATE TABLE [dbo].[TileSet] (
    [Id] uniqueidentifier  NOT NULL,
    [X] smallint  NOT NULL,
    [Y] smallint  NOT NULL,
    [GraphicTile] smallint  NOT NULL,
    [TileType_Id] uniqueidentifier  NOT NULL,
    [Place_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'TileTypeSet'
CREATE TABLE [dbo].[TileTypeSet] (
    [Id] uniqueidentifier  NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ActionLogSet'
CREATE TABLE [dbo].[ActionLogSet] (
    [Id] uniqueidentifier  NOT NULL,
    [TimeStamp] datetime  NOT NULL,
    [Character_Id] uniqueidentifier  NOT NULL,
    [Tile_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'IslandQueSet'
CREATE TABLE [dbo].[IslandQueSet] (
    [Id] uniqueidentifier  NOT NULL,
    [IslandId] uniqueidentifier  NOT NULL,
    [CharacterId] uniqueidentifier  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'UserAccountSet'
ALTER TABLE [dbo].[UserAccountSet]
ADD CONSTRAINT [PK_UserAccountSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CharacterSet'
ALTER TABLE [dbo].[CharacterSet]
ADD CONSTRAINT [PK_CharacterSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CharacterItemSet'
ALTER TABLE [dbo].[CharacterItemSet]
ADD CONSTRAINT [PK_CharacterItemSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ItemTypeSet'
ALTER TABLE [dbo].[ItemTypeSet]
ADD CONSTRAINT [PK_ItemTypeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PlaceSet'
ALTER TABLE [dbo].[PlaceSet]
ADD CONSTRAINT [PK_PlaceSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'IslandSet'
ALTER TABLE [dbo].[IslandSet]
ADD CONSTRAINT [PK_IslandSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TileSet'
ALTER TABLE [dbo].[TileSet]
ADD CONSTRAINT [PK_TileSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TileTypeSet'
ALTER TABLE [dbo].[TileTypeSet]
ADD CONSTRAINT [PK_TileTypeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ActionLogSet'
ALTER TABLE [dbo].[ActionLogSet]
ADD CONSTRAINT [PK_ActionLogSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'IslandQueSet'
ALTER TABLE [dbo].[IslandQueSet]
ADD CONSTRAINT [PK_IslandQueSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Character_Id] in table 'CharacterItemSet'
ALTER TABLE [dbo].[CharacterItemSet]
ADD CONSTRAINT [FK_CharacterCharacterItem]
    FOREIGN KEY ([Character_Id])
    REFERENCES [dbo].[CharacterSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CharacterCharacterItem'
CREATE INDEX [IX_FK_CharacterCharacterItem]
ON [dbo].[CharacterItemSet]
    ([Character_Id]);
GO

-- Creating foreign key on [ItemType_Id] in table 'CharacterItemSet'
ALTER TABLE [dbo].[CharacterItemSet]
ADD CONSTRAINT [FK_ItemTypeCharacterItem]
    FOREIGN KEY ([ItemType_Id])
    REFERENCES [dbo].[ItemTypeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ItemTypeCharacterItem'
CREATE INDEX [IX_FK_ItemTypeCharacterItem]
ON [dbo].[CharacterItemSet]
    ([ItemType_Id]);
GO

-- Creating foreign key on [Character_Id] in table 'ActionLogSet'
ALTER TABLE [dbo].[ActionLogSet]
ADD CONSTRAINT [FK_CharacterActionLog]
    FOREIGN KEY ([Character_Id])
    REFERENCES [dbo].[CharacterSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CharacterActionLog'
CREATE INDEX [IX_FK_CharacterActionLog]
ON [dbo].[ActionLogSet]
    ([Character_Id]);
GO

-- Creating foreign key on [TileType_Id] in table 'TileSet'
ALTER TABLE [dbo].[TileSet]
ADD CONSTRAINT [FK_TileTypeTile]
    FOREIGN KEY ([TileType_Id])
    REFERENCES [dbo].[TileTypeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TileTypeTile'
CREATE INDEX [IX_FK_TileTypeTile]
ON [dbo].[TileSet]
    ([TileType_Id]);
GO

-- Creating foreign key on [Place_Id] in table 'TileSet'
ALTER TABLE [dbo].[TileSet]
ADD CONSTRAINT [FK_PlaceTile]
    FOREIGN KEY ([Place_Id])
    REFERENCES [dbo].[PlaceSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PlaceTile'
CREATE INDEX [IX_FK_PlaceTile]
ON [dbo].[TileSet]
    ([Place_Id]);
GO

-- Creating foreign key on [Tile_Id] in table 'ActionLogSet'
ALTER TABLE [dbo].[ActionLogSet]
ADD CONSTRAINT [FK_TileActionLog]
    FOREIGN KEY ([Tile_Id])
    REFERENCES [dbo].[TileSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TileActionLog'
CREATE INDEX [IX_FK_TileActionLog]
ON [dbo].[ActionLogSet]
    ([Tile_Id]);
GO

-- Creating foreign key on [UserAccount_Id] in table 'CharacterSet'
ALTER TABLE [dbo].[CharacterSet]
ADD CONSTRAINT [FK_UserAccountCharacter]
    FOREIGN KEY ([UserAccount_Id])
    REFERENCES [dbo].[UserAccountSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserAccountCharacter'
CREATE INDEX [IX_FK_UserAccountCharacter]
ON [dbo].[CharacterSet]
    ([UserAccount_Id]);
GO

-- Creating foreign key on [Character_Id] in table 'PlaceSet'
ALTER TABLE [dbo].[PlaceSet]
ADD CONSTRAINT [FK_PlaceCharacter]
    FOREIGN KEY ([Character_Id])
    REFERENCES [dbo].[CharacterSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PlaceCharacter'
CREATE INDEX [IX_FK_PlaceCharacter]
ON [dbo].[PlaceSet]
    ([Character_Id]);
GO

-- Creating foreign key on [IslandId] in table 'PlaceSet'
ALTER TABLE [dbo].[PlaceSet]
ADD CONSTRAINT [FK_IslandPlace]
    FOREIGN KEY ([IslandId])
    REFERENCES [dbo].[IslandSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_IslandPlace'
CREATE INDEX [IX_FK_IslandPlace]
ON [dbo].[PlaceSet]
    ([IslandId]);
GO

-- Creating foreign key on [IslandId] in table 'IslandQueSet'
ALTER TABLE [dbo].[IslandQueSet]
ADD CONSTRAINT [FK_IslandIslandQue]
    FOREIGN KEY ([IslandId])
    REFERENCES [dbo].[IslandSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_IslandIslandQue'
CREATE INDEX [IX_FK_IslandIslandQue]
ON [dbo].[IslandQueSet]
    ([IslandId]);
GO

-- Creating foreign key on [CharacterId] in table 'IslandQueSet'
ALTER TABLE [dbo].[IslandQueSet]
ADD CONSTRAINT [FK_CharacterIslandQue]
    FOREIGN KEY ([CharacterId])
    REFERENCES [dbo].[CharacterSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CharacterIslandQue'
CREATE INDEX [IX_FK_CharacterIslandQue]
ON [dbo].[IslandQueSet]
    ([CharacterId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------